#include "game_version.h"
#include "game_yml.h"
#include "game_file.h"
#include "game_log.h"
#include <unistd.h>

#define ASSERT(foo) \
  if (!(foo)) { __log("FAIL: %s\n", #foo); abort(); }

int main()
{
  __vprint();

  char cc[C_MAX_FILENAME];
  __getcwd(cc,C_MAX_FILENAME);
  __log("cwd: %s\n",cc);

  std::string filename{cc};
  filename += "/example/sample.yml";

  CGameYML yml;
  ASSERT(yml.load(filename.c_str()));
  yml.trace(stdout);

  __log("test0");
  {
    std::string appname = yml.getString("app/name", "");
    ASSERT(appname == "appname");

    UINT32 myint = yml.getUINT32("app/myint", 0);
    ASSERT(myint == 12345);

  }
  __log("ok");

  __log("test1");
  {
    std::string name, passwd;

    __log("test1.1");
    name = yml.getString("user/.0/username", "");
    passwd = yml.getString("user/.0/password", "");
    __log("name: %s, passwd: %s", name.c_str(), passwd.c_str());
    ASSERT(name == "u1");
    ASSERT(passwd == "12345678");

    __log("test1.2");
    name = yml.getString("user/.1/username", "");
    passwd = yml.getString("user/.1/password", "");
    __log("name: %s, passwd: %s", name.c_str(), passwd.c_str());
    ASSERT(name == "u2");
    ASSERT(passwd == "12345678");

    __log("test1.3");
    name = yml.getString("user/.2/username", "");
    passwd = yml.getString("user/.2/password", "");
    __log("name: %s, passwd: %s", name.c_str(), passwd.c_str());
    ASSERT(name == "");
    ASSERT(passwd == "");
  }
  __log("ok");

}
